ROOT=.

INCLUDE_DIR = include
vpath %.h $(INCLUDE_DIR) ModuleA ModuleB build
export INCLUDE_DIR
LIBS := $(LIBS_ENV)
#LIBS := $(subst %:%, % %, $(LIBS_ENV))
CC=gcc
CFLAGS = -I $(INCLUDE_DIR) -Wall -g 
SUBDIRS := $(ROOT)/ModuleA $(ROOT)/ModuleB
SOURCES := $(wildcard *.c)
CHEADERS := $(wildcard *.h)

objects := $(patsubst %.c,%.o,$(wildcard *.c))  
RM = rm -rf
target = Managementofsc.out

MAKE = make
  
all: $(target)

$(objects) : main.c link.h stu.h stu_pub.h cou.h cou_pub.h
	$(CROSS_COMPILE)gcc -c $(CFLAGS) $< -o $@  

$(target): $(objects)
	for dir in $(SUBDIRS); do $(MAKE) -C $$dir all || exit 1; done
	$(CC) $(CFLAGS) $^ -o $@ $(LIBS)

clean:
	@for dir in $(SUBDIRS); do make -C $$dir clean|| exit 1; done
	$(RM) $(objects) $(LIBS) $(target)

.PHONY: all clean 
